/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package meteocal.entity;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import meteocal.utility.DateManager;
import meteocal.weather.Weather;

/**
 *
 * @author andrea
 */
@Entity
public class Event implements Serializable {
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;    
    @NotNull
    @ManyToOne
    @JoinColumn(referencedColumnName = "email")
    private Users creator;    
    @NotNull(message="Required field")
    private String title;
    @NotNull(message="Required field")
    private String place;
    @NotNull(message="Required field")
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar startTime;
    @NotNull(message="Required field")
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar endTime;
    @NotNull(message="Required field")
    private boolean visible;
    @NotNull
    private boolean outdoor;
    @NotNull
    private Weather badWeather;
    
    /*
        Getters and Setters
    */
    public Users getCreator() {
        return creator;
    }

    public void setCreator(Users creator) {
        this.creator = creator;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getPlace() {
        return place;
    }

    public void setPlace(String place) {
        this.place = place;
    }

    public Calendar getStartTime() {
        return startTime;
    }

    public void setStartTime(Calendar startTime) {
        this.startTime = startTime;
    }

    public Calendar getEndTime() {
        return endTime;
    }

    public void setEndTime(Calendar endTime) {
        this.endTime = endTime;
    }

    public boolean isVisible() {
        return visible;
    }

    public void setVisible(boolean visible) {
        this.visible = visible;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    public Weather getBadWeather() {
        return badWeather;
    }
    
    public void setBadWeather(Weather badWeather) {
        this.badWeather = badWeather;
    }

    public boolean isOutdoor() {
        return outdoor;
    }

    public void setOutdoor(boolean outdoor) {
        this.outdoor = outdoor;
    }   

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Event other = (Event) obj;
        return Objects.equals(this.id, other.id);
    }
    
    

    @Override
    public String toString() {
        return String.format("%s, %s\nBegin: %s\tEnd: %s",
                title,
                place,
                DateManager.calendarToString(startTime),
                DateManager.calendarToString(endTime));
    }
    
}
